package top.imyzt.util;

import java.util.Random;
import java.util.UUID;

/**
 * 随机生成指定内容
 * @author imyzt
 *
 */
public class RandomUtils {

	/**
	 * 生成32位UUID
	 * @return
	 */
	public static String createUUID(){
		return UUID.randomUUID().toString().replaceAll("-", "");
	}
	
	/**
	 * 生成指定长度随机字符串
	 * @param len 随机字符串长度
	 * <br/>
	 * <code>
	 * len < 1 ? 4 : len
	 * </code>
	 * @return
	 */
	public static String createRandom(int len){
		len = len < 1 ? 4 : len;
		
		String str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
		StringBuffer sb = new StringBuffer();
		Random random=new Random();
		for (int i = 0; i < len; i++) {
			int num = random.nextInt(str.length());
			sb.append(str.charAt(num));
		}
		return sb.toString();
	}
	
	/**
	 * 指定最大值.生成随机数
	 * @param maxValue 最大值
	 * @return
	 */
	public static int createRondomByMaxValue(int maxValue){
		Random random = new Random();
		if (maxValue == 0) {
			return 0;
		}
		
		if (maxValue < 0) {
			return -random.nextInt(-maxValue);
		}
		return random.nextInt(maxValue);
	}
	
	
	public static void main(String[] args) {
		for (int i = 0; i < 122; i++) {
			System.out.println(createRondomByMaxValue(-122));
		}
	}
	
}
